<html>
<head><meta charset="utf-8"><title>where do we talk about performance (of generated code)? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html">where do we talk about performance (of generated code)?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227180852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227180852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227180852">(Feb 21 2021 at 17:13)</a>:</h4>
<p>Is there a stream/thread we are talking about <a href="https://github.com/rust-lang/rust/pull/81782#issuecomment-780193354">https://github.com/rust-lang/rust/pull/81782#issuecomment-780193354</a>? cc <span class="user-mention" data-user-id="116122">@simulacrum</span> <br>
I see wg-performance is about the perf of compile times, not generated code</p>



<a name="227180886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227180886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227180886">(Feb 21 2021 at 17:13)</a>:</h4>
<p>Not currently, but that is really a compile times point I think? i.e., jemalloc for rustc is the only thing that thread touches</p>



<a name="227181262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227181262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227181262">(Feb 21 2021 at 17:20)</a>:</h4>
<p>oh i see. where does rustc make jemalloc the default allocator for  binaries it produces? <a href="https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17">https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17</a> suggests that jemalloc is the default on some platforms, have we checked if we correctly use sdallocx there? (interestingly, jemallocator appears to do the correct thing? <a href="https://docs.rs/jemallocator/0.3.2/src/jemallocator/lib.rs.html#100">https://docs.rs/jemallocator/0.3.2/src/jemallocator/lib.rs.html#100</a>)</p>



<a name="227181644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227181644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227181644">(Feb 21 2021 at 17:27)</a>:</h4>
<p>Do we like...override the libc symbols with jemalloc ones? <a href="https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/alloc.rs#L42">https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/alloc.rs#L42</a></p>



<a name="227181873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227181873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227181873">(Feb 21 2021 at 17:31)</a>:</h4>
<p>omg i read that competeeelty wrong, it said switched FROM jemalloc to default system allocator lol<br>
That said, we should def do a perf run where we use sdallocx. I wonder why we don't just use #[global_allocator] inside the rustc main</p>



<a name="227183192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227183192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227183192">(Feb 21 2021 at 17:55)</a>:</h4>
<p>one reason is there's the fear there's cases where we allocate memory in rustc/free in llvm and vice versa. but also overriding the global C allocator. i don't know if this fear is founded, but it's been cited several times in the past.</p>
<p>that said, overridign the system malloc is not really viable on some platforms (on macos — see some of my comments here: <a href="https://github.com/purpleprotocol/mimalloc_rust/issues/41">https://github.com/purpleprotocol/mimalloc_rust/issues/41</a>)... so #[global_allocator] would be better.</p>



<a name="227185621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227185621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227185621">(Feb 21 2021 at 18:37)</a>:</h4>
<p>should we try swapping the way we do it now with #[global_allocator] = jemallocator and see if anything breaks?</p>



<a name="227189043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227189043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227189043">(Feb 21 2021 at 19:37)</a>:</h4>
<p><code>#[global_allocator]</code> doesn't work when dynamically linking to <a href="http://libstd.so">libstd.so</a>.</p>



<a name="227194248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227194248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227194248">(Feb 21 2021 at 21:10)</a>:</h4>
<p>so moving rustc to use jemalloc is going to require like...<code>cfg(jemalloc_sys)</code> in the unix GlobalAlloc impl?</p>



<a name="227195255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195255">(Feb 21 2021 at 21:30)</a>:</h4>
<p><code>rustc</code> can be configured to use jemalloc itself -- some of the CI dist builders do this</p>



<a name="227195312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195312">(Feb 21 2021 at 21:30)</a>:</h4>
<p>But it was an explicit decision that the default for user code should be the system allocator</p>



<a name="227195525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195525">(Feb 21 2021 at 21:34)</a>:</h4>
<p>Oh, I misunderstood @_bjorn3's point... that is tricky.</p>



<a name="227195728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195728">(Feb 21 2021 at 21:39)</a>:</h4>
<p>Is the way rustc currently uses jemalloc to basically override the libc symbols? if thats true...then switching to <code>sdallocx</code> is going to be....not ez</p>



<a name="227195742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195742">(Feb 21 2021 at 21:39)</a>:</h4>
<p>yes</p>



<a name="227195934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227195934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227195934">(Feb 21 2021 at 21:43)</a>:</h4>
<p>wouldn't that require make the <a href="http://libstd.so">libstd.so</a> depend on a libc where we have add the sdallocx symbol or something?</p>



<a name="227196248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227196248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227196248">(Feb 21 2021 at 21:48)</a>:</h4>
<p>Perhaps it could have weak-null symbols of its own</p>



<a name="227198001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227198001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227198001">(Feb 21 2021 at 22:06)</a>:</h4>
<p>Oh weak symbols is an interesting idea...</p>



<a name="227480311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227480311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Patrick Walton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227480311">(Feb 23 2021 at 18:32)</a>:</h4>
<p>My feeling is that if we aren't on sized deallocation in the compiler then that is a bug that needs fixing. We don't want to leave compiler performance on the table and sized deallocation is algorithmically a significant win for typical malloc techniques.</p>



<a name="227482916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227482916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227482916">(Feb 23 2021 at 18:48)</a>:</h4>
<p>Do you happen to have on hand something that explains why it's so important? I'm not disagreeing, I just want to read about it.</p>



<a name="227483412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227483412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227483412">(Feb 23 2021 at 18:51)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu Nicola</span> <a href="https://github.com/jemalloc/jemalloc/issues/28">https://github.com/jemalloc/jemalloc/issues/28</a> links to <a href="https://isocpp.org/files/papers/n3778.html">https://isocpp.org/files/papers/n3778.html</a> which says<br>
"Modern memory allocators often allocate in size categories, and, for space efficiency reasons, do not store the size of the object near the object." which i suppose means sized deallocation don't have to traverse a different datastructure to find the size</p>



<a name="227488197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227488197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Patrick Walton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227488197">(Feb 23 2021 at 19:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="203546">Laurențiu Nicola</span> <a href="#narrow/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F/near/227482916">said</a>:</p>
<blockquote>
<p>Do you happen to have on hand something that explains why it's so important? I'm not disagreeing, I just want to read about it.</p>
</blockquote>
<p>Daniel Micay was a big advocate of this (rightly so IMO) and had some performance numbers as I recall. I don't have them offhand but they were significant.</p>



<a name="227491186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227491186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Patrick Walton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227491186">(Feb 23 2021 at 19:42)</a>:</h4>
<p>And yeah, the reason is that the allocator doesn't have to go search some sort of data structure that maps blocks to sizes. It's wasteful to do that at runtime since the compiler already statically knows the size of what's to be deallocated.</p>



<a name="227491342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227491342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227491342">(Feb 23 2021 at 19:43)</a>:</h4>
<p>Ah, I see. I guess it was storing the size next to the block in my mental model.</p>



<a name="227491438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227491438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227491438">(Feb 23 2021 at 19:43)</a>:</h4>
<p>mimalloc manages without it, but yeah, jemalloc needs the size. One of the reasons I prefer using mimalloc is that it's fully compatible with the normal malloc/free interface and doesn't really require using extensions to get good perf</p>



<a name="227493393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227493393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Patrick Walton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227493393">(Feb 23 2021 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F/near/227491438">said</a>:</p>
<blockquote>
<p>mimalloc manages without it, but yeah, jemalloc needs the size. One of the reasons I prefer using mimalloc is that it's fully compatible with the normal malloc/free interface and doesn't really require using extensions to get good perf</p>
</blockquote>
<p>Note that Daniel's position was that sized deallocation opens the door to some potential faster allocator designs, which seems interesting</p>



<a name="227496598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227496598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227496598">(Feb 23 2021 at 20:17)</a>:</h4>
<p>Right, the general rust allocator api supports this — in fact global and (unstable) local allocators <em>only</em> allow for sized deallocation.</p>
<p>At the end of the day though, a decent chunk of rustc's allocations come from LLVM, which will only use plain <code>free</code> (or delete sometimes), and so we're kinda bounded by that in some respect (that said It also seems hard to switch rustc itself generally to use a sized deallocation).</p>
<p>If LLVM didn't do this, and had an easier way to swap allocators other than "swap the libc allocator/override global operator new/delete", we'd have a lot more flexibility in how rustc can use allocators. But, it's not really a trivial change (I looked into it at once point).</p>



<a name="227498227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227498227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227498227">(Feb 23 2021 at 20:28)</a>:</h4>
<p>IIRC the reason jemalloc isn't registered as the rust-side global allocator in rustc is that rustc is dynamically linked and the infrastructure isn't built to support that well?</p>



<a name="227498344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227498344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227498344">(Feb 23 2021 at 20:29)</a>:</h4>
<p>i remember hearing there was also concerns about memory allocated in rustc, deallocated in llvm, or vice versa. i would consider this a bug, but <span class="user-mention" data-user-id="132920">@gnzlbg</span> mentioned it at one point in the past.</p>



<a name="227498497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227498497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227498497">(Feb 23 2021 at 20:30)</a>:</h4>
<p>that said, generating IR allocates a bunch IIRC, and so it would be unfortunate for all those allocations not to use a better allocator.</p>



<a name="227498715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227498715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227498715">(Feb 23 2021 at 20:32)</a>:</h4>
<p>I would be very surprised we did this (allocate in rustc, deallocate in LLVM) except maybe for cstrings we pass into llvm?</p>



<a name="227499705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227499705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227499705">(Feb 23 2021 at 20:40)</a>:</h4>
<blockquote>
<p>i remember hearing there was also concerns about memory allocated in rustc, deallocated in llvm, or vice versa. </p>
</blockquote>
<p>Would that be a problem as long as C symbols are overridden so that they point to the same allocators as <code>#[global_allocator]</code>?</p>



<a name="227501000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227501000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227501000">(Feb 23 2021 at 20:50)</a>:</h4>
<p>No, but at that point there's less of a benefit. I guess it means rust allocations would get to used the sized deallocation api though.</p>



<a name="227504876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227504876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227504876">(Feb 23 2021 at 21:18)</a>:</h4>
<p>Yeah, the point of setting the global allocator would be to use the sized API, but if LLVM is just passing the pointers to free those allocations couldn't use that API</p>



<a name="227505101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227505101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227505101">(Feb 23 2021 at 21:19)</a>:</h4>
<p>But if the set of allocations that work like that are small, then it'd be easy to explicitly malloc in those instances</p>



<a name="227514814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227514814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227514814">(Feb 23 2021 at 22:20)</a>:</h4>
<p>One question I do have -- is the sized API perhaps usable in an optional way? Intuitively you don't get all the wins if you have to support both in the allocator, but it seems like some amount of traversal/cost of deallocation may be avoidable if that information is provided</p>



<a name="227515809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227515809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227515809">(Feb 23 2021 at 22:27)</a>:</h4>
<p><span class="user-mention" data-user-id="330154">@The 8472</span>  my understanding is overriding the symbols is how rustc uses jemalloc today, but jemalloc exposes a non-standard api called sdallocx which is free that takes the size as well</p>
<p><span class="user-mention" data-user-id="243558">@Steven Fackler</span> yeah thats my understanding as well, we aren't sure if global_allocator would work in rust</p>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I think that would mean we would need to optionally use sdallocx here: <a href="https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/alloc.rs#L42">https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/alloc.rs#L42</a> somehow? unless i am totally off about how rustc uses jemalloc?</p>



<a name="227515985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227515985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227515985">(Feb 23 2021 at 22:28)</a>:</h4>
<p>If rustc were to use jemalloc as the global allocator it'd do it through something like the jemallocator crate, not by modifying the System type</p>



<a name="227516055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227516055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227516055">(Feb 23 2021 at 22:29)</a>:</h4>
<p>right, I'm trying to understand if we actually need to know if we don't pass pointers to llvm which calls free</p>



<a name="227516157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227516157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227516157">(Feb 23 2021 at 22:30)</a>:</h4>
<p>i.e., if we override the global allocator like we do today in rustc (via symbols) and also do so via #[global_allocator] (after fixing the dynamic linking issues), would that be fine?</p>



<a name="227518441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227518441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227518441">(Feb 23 2021 at 22:49)</a>:</h4>
<p>I believe so? any extraneous free calls in llvm or whatever would be fine but most deallocs would go through the global_allocator dealloc impl that correctly uses sdallocx<br>
I can't think of a reason why doing both would break anything, as long as we know the symbols in both cases are the same</p>



<a name="227518498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227518498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227518498">(Feb 23 2021 at 22:49)</a>:</h4>
<p>free calls in llvm of memory allocated by the sized APIs in rustc would be very not fine</p>



<a name="227518693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227518693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227518693">(Feb 23 2021 at 22:51)</a>:</h4>
<p>oh actually maybe it is fine</p>



<a name="227518809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227518809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227518809">(Feb 23 2021 at 22:52)</a>:</h4>
<p>it doesn't look like jemalloc's man page says anything about the nonstandard API being totally separate from the standard API</p>



<a name="227518974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227518974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227518974">(Feb 23 2021 at 22:53)</a>:</h4>
<p>it should be fine</p>



<a name="227519055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519055">(Feb 23 2021 at 22:54)</a>:</h4>
<p>though the existence of dallocx is a bit worrying WRT the flags rather than the size</p>



<a name="227519137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519137">(Feb 23 2021 at 22:54)</a>:</h4>
<p>but I don't know if alignment in particular is important there rather than the tcache/arena or whatever else</p>



<a name="227519395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519395">(Feb 23 2021 at 22:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="243558">Steven Fackler</span> <a href="#narrow/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F/near/227518498">said</a>:</p>
<blockquote>
<p>free calls in llvm of memory allocated by the sized APIs in rustc would be very not fine</p>
</blockquote>
<p>it would be nice if we could be sure we dont do this, since that would allow using a better allocator at least for rust code on platforms where the global override of libc malloc isnt viable (macos, for example)</p>



<a name="227519437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519437">(Feb 23 2021 at 22:56)</a>:</h4>
<p>you can override macos's allocator via zone stuff, which jemalloc does</p>



<a name="227519710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519710">(Feb 23 2021 at 22:58)</a>:</h4>
<p>the performance there isn't great, and even then you have to be able to handle a lot of weird edge cases. for example, your alloc_size api has to return 0 for allocations performed by different zones (since free calls each zone in the zone list until it finds a zone that "claims" the pointer). this tends to break external allocators</p>



<a name="227519958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227519958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227519958">(Feb 23 2021 at 23:00)</a>:</h4>
<p>and system apis will allocate out of specific zones and then free using the normal free, for example: <a href="https://github.com/opensource-apple/objc4/blob/master/runtime/hashtable2.mm#L62-L68">https://github.com/opensource-apple/objc4/blob/master/runtime/hashtable2.mm#L62-L68</a>. some of these allocations come very early, e.g. during loading by dyld, so you can't rely on always being the default zone in general.</p>



<a name="227685403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20do%20we%20talk%20about%20performance%20%28of%20generated%20code%29%3F/near/227685403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20do.20we.20talk.20about.20performance.20(of.20generated.20code).3F.html#227685403">(Feb 24 2021 at 22:26)</a>:</h4>
<p>should this thread be moved to t-compiler/performance?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>